package cn.wolfcode.wms.web.controller;


import cn.wolfcode.wms.domain.Depot;
import cn.wolfcode.wms.query.QueryObject;
import cn.wolfcode.wms.service.IDepotService;
import cn.wolfcode.wms.util.JSONResult;
import cn.wolfcode.wms.util.NeedPermission;
import cn.wolfcode.wms.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("depot")
public class DepotController {
    @Autowired
    private IDepotService depotService;

    @RequestMapping("list")
    public String list(@ModelAttribute("qo") QueryObject qo, Model model){
        PageResult pageResult = depotService.queryResult(qo);
        model.addAttribute("result",pageResult);

        return "depot/list";
    }

    @RequestMapping("input")
    public String input(Model model,Long id){

        if (id != null) {
            model.addAttribute("entity",depotService.get(id));
        }

        return "depot/input";
    }

    @RequestMapping("delete")
    @ResponseBody
    public Object delete(Long id){

        depotService.delete(id);

        return new JSONResult();
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Depot d){

        depotService.saveOrUpdate(d);

        return new JSONResult();//象征想返回
    }
}
